package zhaoq_hero.mymv.utils;

import android.content.Context;
import android.os.Environment;
import android.util.Log;

import java.io.File;

/**
 * Project_name : MyMv
 * Author : zhaoQiang
 * Date : 2015/10/29,15:28
 * Email : zhaoq_hero@163.com
 */
public class FileUtils {

    private FileUtils(){}

    public static File getMediaRecorderFolder(Context context){
        File targetFile = null;

        File dir = null;

        //获取状态：
        String state = Environment.getExternalStorageState();

        if (state.equals(Environment.MEDIA_MOUNTED)){
            //获取   公共照相机拍照存储文件的位置：
            dir = Environment.getExternalStoragePublicDirectory(
                    Environment.DIRECTORY_DCIM);

            if (!dir.exists()){
                //公共 位置不存在   那就指定特定目录：
                dir = Environment.getExternalStorageDirectory();

                Log.i("info","外部存储目录存在。。。");
                //公共位置不存在   那就指定特定目录
                dir = new File(dir,"TestDIOM");

                if (!dir.exists()){
                    dir.mkdirs();
                }

            }

            Log.i("info","电子啦挂在。。。");

        }else{
            dir = context.getFilesDir();
            Log.i("info","没有挂在文件。。。");
        }

        targetFile = new File(dir,"video"+System.currentTimeMillis()+".mp4");


        return targetFile;
    }


    public static File getImageFile(Context context) {

        File targetFile = null;
        String state = Environment.getExternalStorageState();

        File dir = null;
        if (state.equals(Environment.MEDIA_MOUNTED)) {

            //获取公共的照相机拍照存储文件的位置
            dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
            if (!dir.exists()) {

                //因为公共的拍照位置不存在
                //获取存储卡的特定目录
                dir = Environment.getExternalStorageDirectory();
                dir = new File(dir, "MediaRecorder/Images");

                if (!dir.exists()) {
                    dir.mkdirs();
                    Log.d("dir", dir.getAbsolutePath());
                }
            }
        } else {
            //获取内部存储区
            dir = context.getFilesDir();
            Log.d("dir", dir.getAbsolutePath());
        }

        //最终目标文件的位置
        targetFile = new File(dir, "Image-" + System.currentTimeMillis() + ".jpg");

        return targetFile;
    }
}


